<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

	private $Verify = '';
	public function _initialize(){
		if($this->Verify==''){
			$config =    array(    
				'fontSize'    =>    30,    // 验证码字体大小    
				'length'      =>    2,     // 验证码位数    
				'useNoise'    =>    false, // 关闭验证码杂点
			);
			$this->Verify = new \Think\Verify($config);
		}
	}

	public function vcode(){
		$this->Verify->entry();
	}

	public function login(){
		$this->display();
	}

	public function login_c(){
		$name = I('post.user_name');
		$pwd = I('post.user_pwd');
		$code = I('post.code');
		if(!$name || !$pwd || !$code){
			//echo "<script>alert('数据不得为空！');history.go(-1);</script>";exit;
		}
		if(!$this->Verify->check($code)){
			//echo "<script>alert('验证码不正确！');history.go(-1);</script>";exit;
		}
		$m = M('Think_auth_user');

		$res_User = $m->where(array('name'=>$name))->find();
		if($res_User){
			if($res_User['pwd'] == Encrypt($pwd)){
				session('uid',$res_User['id']);
				session('UserInfo',$res_User);
				header('location:'.U('Index/index'));exit;
			}
		}
		echo "<script>alert('用户名或密码不正确！');history.go(-1);</script>";exit;
	}


	public function user_exit(){
		session('uid',null);
		session('UserInfo',null);
	}

}